package com.houdoudou.servlet.jsp;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.houdoudou.affair.jsp.Common;
import com.houdoudou.affair.jsp.DatabaseAffairJsp;
import com.houdoudou.affair.jsp.ProgrammerAffairJsp1;
import com.houdoudou.affair.jsp.ProgrammerAffairJsp2;

public class Programmer4Jsp extends HttpServlet{

	private static final long serialVersionUID = 7L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		process(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		process(req, resp);
	}
	
	void process(HttpServletRequest req, HttpServletResponse resp){
		
		String affair="";
		    try {
				req.setCharacterEncoding("UTF-8");
				  resp.setCharacterEncoding("UTF-8");
					 affair=req.getParameter("affair");
					 System.out.println("affair="+affair + "  时间----"+ new Date());
		    } catch (UnsupportedEncodingException e) {
			    // TODO Auto-generated catch block
		    	 String jumpJspPath="/programmer/basicResult.jsp";
		    	  String errorInfo="无法解析事件";
					Common.forwardToJsp(req,resp,jumpJspPath,errorInfo);
			    e.printStackTrace();
			    return;
	         	 }	 
					 
		 //新增业主
		 if(affair.equals("createOwner")){ 
			  ProgrammerAffairJsp1.createOwner(req, resp);
		 }// 搜索业主
		 else if(affair.equals("searchOwner")){
			ProgrammerAffairJsp1.searchOwner(req, resp); 
		 }// 修改业主
		 else if(affair.equals("modifyOwner")){
			ProgrammerAffairJsp1.modifyOwner(req, resp); 
		 }//更新业主
		 else if(affair.equals("updateOwner")){
				ProgrammerAffairJsp1.updateOwner(req, resp); 
		 }//新建自提柜
		 else if(affair.equals("createMachine")){
				ProgrammerAffairJsp1.createMachine(req, resp); 
		 }//增补创建箱格
		 else if(affair.equals("addCreateBox")){
				ProgrammerAffairJsp1.addCreateBox(req, resp);
			 } //搜索自提柜
		 else if(affair.equals("searchMachine")){
				ProgrammerAffairJsp1.searchMachine(req, resp); 
			 }//搜索自提柜
		 else if(affair.equals("searchBox")){
				ProgrammerAffairJsp1.searchBox(req, resp); 
			 }//更新自提柜
		 else if(affair.equals("updateBox")){
				ProgrammerAffairJsp1.updateBox(req, resp); 
			 }//修改自提柜
		 else if(affair.equals("modifyMachine")){
				ProgrammerAffairJsp1.modifyMachine(req, resp); 
			 }//更新自提柜
		 else if(affair.equals("updateMachine")){
				ProgrammerAffairJsp1.updateMachine(req, resp); 
			 }//查看自提柜
		 else if(affair.equals("detailMachine")){
				ProgrammerAffairJsp1.detailMachine(req, resp); 
			 }//删除自提柜
		 else if(affair.equals("deleteMachine")){
				ProgrammerAffairJsp1.deleteMachine(req, resp); 
			 }//新增商家searchSupplier
		 else if(affair.equals("createSupplier")){
				ProgrammerAffairJsp2.createSupplier(req, resp);
			 }//搜索商家
		 else if(affair.equals("searchSupplier")){
				ProgrammerAffairJsp2.searchSupplier(req, resp);
			 }//修改商家
		 else if(affair.equals("modifySupplier")){
				ProgrammerAffairJsp2.modifySupplier(req, resp);
			 }//更新商家
		 else if(affair.equals("updateSupplier")){
				ProgrammerAffairJsp2.updateSupplier(req, resp);
			 }//删除商家
		 else if(affair.equals("deleteSupplier")){
				ProgrammerAffairJsp2.deleteSupplier(req, resp);
			 }
		 
		 else{
			 String jumpJspPath="/programmer/basicResult.jsp";
			 String errorInfo="事件   "+ affair  +"未定义";
				Common.forwardToJsp(req,resp,jumpJspPath,errorInfo); 
		 }
		 
		    }
	
	
}
